$(function() {

	function judgeDefaultData(defaultData, i) {//默认选择
		if (defaultData.attr('defaultData') == 0) {
			defaultData.css("color", "red");
		} else {
			defaultData.css("color", "#666666");
		}
		if (defaultData.attr('defaultData') == i) {
			defaultData.children().eq(i).attr('selected', 'true');
		}
	}

	for (var i = 0; i < 17; i++) {
		judgeDefaultData($("#sel_child"), i);
		judgeDefaultData($("#sel_diffArea"), i);
		judgeDefaultData($("#sel_likeType"), i);
		judgeDefaultData($("#sel_sexBefore"), i);
		judgeDefaultData($("#sel_liveWithParents"), i);
		judgeDefaultData($("#sel_sexyPart"), i);
	}

	function checkBox(box) {
		var boxs = $(box).attr('defaultData').split("-");
		for (var i = 0; i < boxs.length; i++) {
			if (boxs[i] == '1') {
				$(box + " li").eq(i).find('input').attr('checked', 'checked');
			}
		}
	}

	checkBox('#chk_interests');
	checkBox('#chk_personalitys');

	function checkStr(str) {//获取选择框
		var checkString = '';
		$(str + " li").each(function() {
			if ($(this).find('input').prop("checked") == true) {
				checkString += '1-';
			} else {
				checkString += '0-';
			}
		});
		return checkString.substr(0, checkString.length - 1);
	}


	$('.checkBox').click(function() {
		$(this).find('input').click();
	});
	$('#saveMoreInfoBtn').click(function() {
		$.post("userAjax_updateDetailData", {
			"detailData.ischildren" : $("#sel_child").val(),
			"detailData.distanceLove" : $("#sel_diffArea").val(),
			"detailData.loveType" : $("#sel_likeType").val(),
			"detailData.premaritalSex" : $("#sel_sexBefore").val(),
			"detailData.liveWithParents" : $("#sel_liveWithParents").val(),
			"detailData.charm" : $("#sel_sexyPart").val(),
			"detailData.hobby" : checkStr("#chk_interests"),
			"detailData.personality" : checkStr("#chk_personalitys"),
		}, function(data) {
			if (data != "true") {
				art.dialog.alert('发生未知错误！！！').time(2);
			} else {
				art.dialog.alert('保存成功！！').time(2);
			}
		});
		return false;
	});

});

